<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>get</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.JSON">
<link rel="up" href="../ref.html" title="This Page Intentionally Left Blank 2/2">
<link rel="prev" href="boost__json__value_from/overload2.html" title="value_from (2 of 2 overloads)">
<link rel="next" href="boost__json__generic_category.html" title="generic_category">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost__json__value_from/overload2.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost__json__generic_category.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="json.ref.boost__json__get"></a><a class="link" href="boost__json__get.html" title="get">get</a>
</h4></div></div></div>
<p>
        <a class="indexterm" name="idm62075"></a>
      </p>
<p>
        Tuple-like element access.
      </p>
<h5>
<a name="json.ref.boost__json__get.h0"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.synopsis"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.synopsis">Synopsis</a>
      </h5>
<p>
        Defined in header <code class="literal">&lt;<a href="https://github.com/cppalliance/json/blob/master/include/boost/json/value.hpp" target="_top">boost/json/value.hpp</a>&gt;</code>
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">I</span><span class="special">,</span>
    <span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="emphasis"><em>see-below</em></span>
<span class="identifier">get</span><span class="special">(</span>
    <span class="identifier">T</span><span class="special">&amp;&amp;</span> <span class="identifier">kvp</span><span class="special">);</span>
</pre>
<h5>
<a name="json.ref.boost__json__get.h1"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.description"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.description">Description</a>
      </h5>
<p>
        This overload permits the key and value of a <code class="computeroutput"><span class="identifier">key_value_pair</span></code>
        to be accessed by index. For example:
      </p>
<pre class="programlisting"><span class="identifier">key_value_pair</span> <span class="identifier">kvp</span><span class="special">(</span><span class="string">"num"</span><span class="special">,</span> <span class="number">42</span><span class="special">);</span>

<span class="identifier">string_view</span> <span class="identifier">key</span> <span class="special">=</span> <span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;(</span><span class="identifier">kvp</span><span class="special">);</span>
<span class="identifier">value</span><span class="special">&amp;</span> <span class="identifier">jv</span> <span class="special">=</span> <span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">kvp</span><span class="special">);</span>
</pre>
<h5>
<a name="json.ref.boost__json__get.h2"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.structured_bindings"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.structured_bindings">Structured
        Bindings</a>
      </h5>
<p>
        When using C++17 or greater, objects of type <a class="link" href="boost__json__key_value_pair.html" title="key_value_pair"><code class="computeroutput"><span class="identifier">key_value_pair</span></code></a> may be used to initialize
        structured bindings:
      </p>
<pre class="programlisting"><span class="identifier">key_value_pair</span> <span class="identifier">kvp</span><span class="special">(</span><span class="string">"num"</span><span class="special">,</span> <span class="number">42</span><span class="special">);</span>

<span class="keyword">auto</span><span class="special">&amp;</span> <span class="special">[</span><span class="identifier">key</span><span class="special">,</span> <span class="identifier">value</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">kvp</span><span class="special">;</span>
</pre>
<p>
        Depending on the value of <code class="computeroutput"><span class="identifier">I</span></code>,
        the return type will be:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            <code class="computeroutput"><span class="identifier">string_view</span> <span class="keyword">const</span></code>
            if <code class="computeroutput"><span class="identifier">I</span> <span class="special">==</span>
            <span class="number">0</span></code>, or
          </li>
<li class="listitem">
            <code class="computeroutput"><span class="identifier">value</span><span class="special">&amp;</span></code>,
            <code class="computeroutput"><span class="identifier">value</span> <span class="keyword">const</span><span class="special">&amp;</span></code>, or <code class="computeroutput"><span class="identifier">value</span><span class="special">&amp;&amp;</span></code> if <code class="computeroutput"><span class="identifier">I</span>
            <span class="special">==</span> <span class="number">1</span></code>.
          </li>
</ul></div>
<p>
        Any other value for <code class="computeroutput"><span class="identifier">I</span></code> is
        ill-formed.
      </p>
<h5>
<a name="json.ref.boost__json__get.h3"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.template_parameters"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.template_parameters">Template
        Parameters</a>
      </h5>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Type
                </p>
              </th>
<th>
                <p>
                  Description
                </p>
              </th>
</tr></thead>
<tbody><tr>
<td>
                <p>
                  <code class="computeroutput"><span class="identifier">I</span></code>
                </p>
              </td>
<td>
                <p>
                  The element index to access.
                </p>
              </td>
</tr></tbody>
</table></div>
<h5>
<a name="json.ref.boost__json__get.h4"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.constraints"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.constraints">Constraints</a>
      </h5>
<p>
        <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">is_same_v</span><span class="special">&lt;</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">key_value_pair</span> <span class="special">&gt;</span></code>
      </p>
<h5>
<a name="json.ref.boost__json__get.h5"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.return_value"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.return_value">Return
        Value</a>
      </h5>
<p>
        <code class="computeroutput"><span class="identifier">kvp</span><span class="special">.</span><span class="identifier">key</span><span class="special">()</span></code> if
        <code class="computeroutput"><span class="identifier">I</span> <span class="special">==</span>
        <span class="number">0</span></code>, or <code class="computeroutput"><span class="identifier">kvp</span><span class="special">.</span><span class="identifier">value</span><span class="special">()</span></code> if <code class="computeroutput"><span class="identifier">I</span>
        <span class="special">==</span> <span class="number">1</span></code>.
      </p>
<h5>
<a name="json.ref.boost__json__get.h6"></a>
        <span class="phrase"><a name="json.ref.boost__json__get.parameters"></a></span><a class="link" href="boost__json__get.html#json.ref.boost__json__get.parameters">Parameters</a>
      </h5>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Name
                </p>
              </th>
<th>
                <p>
                  Description
                </p>
              </th>
</tr></thead>
<tbody><tr>
<td>
                <p>
                  <code class="computeroutput"><span class="identifier">kvp</span></code>
                </p>
              </td>
<td>
                <p>
                  The <a class="link" href="boost__json__key_value_pair.html" title="key_value_pair"><code class="computeroutput"><span class="identifier">key_value_pair</span></code></a> object
                  to access.
                </p>
              </td>
</tr></tbody>
</table></div>
<p>
        Convenience header <code class="literal">&lt;<a href="https://github.com/cppalliance/json/blob/master/include/boost/json.hpp" target="_top">boost/json.hpp</a>&gt;</code>
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2019, 2020 Vinnie Falco<br>Copyright © 2020 Krystian Stasiowski<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost__json__value_from/overload2.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost__json__generic_category.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
